package com.base.home.presenter;

import android.app.Activity;

import com.base.commonlib.base.presenter.BasePresenter;
import com.base.commonlib.bean.StatEntity;
import com.base.commonlib.bean.StudyEnent;
import com.base.commonlib.bean.UpdateScopeStatEntity;
import com.base.commonlib.http.RealNetWorkUtil;
import com.base.commonlib.http.utils.CallBackImpl;
import com.base.commonlib.utils.RxBus2;
import com.base.home.view.HomeNewView;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.disposables.Disposable;

/**
 * Created by weikailiang on 2020/3/27.
 */

public class HomeNewPresenter extends BasePresenter<HomeNewView>{
    public HomeNewPresenter(HomeNewView view, Activity activity) {
        super(view, activity);
    }




    /**
     * 积分
     */
    public void getJifeng(String courseRootId,String tenantId,String type){
        Map<String, Object> map = new HashMap<>();
//        if ("95cf0f4698474b37a1c20af89b0b4217".equals(tenantId)){
//            if ("e5405ef33c82470a99b47d489e29f9d9".equals(type)){
//                map.put("settingKey","08020012");
//            }else {
//                map.put("settingKey","08020010");
//            }
//        }else {
//            map.put("settingKey","08020004");
//        }
            if ("e5405ef33c82470a99b47d489e29f9d9".equals(type)){
                map.put("settingKey","08020012");
            }else {
                map.put("settingKey","08020010");
            }
        map.put("funcMainId", "edu");
        map.put("courseRootId", courseRootId);
        Disposable enqueue = RealNetWorkUtil.postContent().method("api-function/integral/save").content(map)
                .build().enqueue(String.class, new CallBackImpl<String>() {
                    @Override
                    public void onError(int code, String msg, String errMsg) {
                    }

                    @Override
                    public void onNext(String str) {
                        if (!str.contains("上限")){
                            mView.showMes(str);
                            RxBus2.getInstance().post(new UpdateScopeStatEntity(1));
                        }

                    }
                });

        mCompositeDisposable.add(enqueue);
    }
    /**
     * 调用已学习接口
     */
    public void toStudy(String id){
        Map<String, Object> map = new HashMap<>();
        map.put("courseId",id);
        Disposable enqueue = RealNetWorkUtil.get().method("api-train/app/addLearn").params(map)
                .build().enqueue(String.class, new CallBackImpl<String>() {
                    @Override
                    public void onError(int code, String msg, String errMsg) {
                        //mView.showError();
                    }

                    @Override
                    public void onNext(String str) {
                        //mView.showMes(str);
                        RxBus2.getInstance().post(new StudyEnent());
                    }
                });

        mCompositeDisposable.add(enqueue);
    }


}
